/*
    XTU OJ: 1356
    by: fifth_light
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct {
    char type;
    int dir;
} tile;

tile maze[100][100];

void reset_maze(int n, int m) {
    for(int i = 0; i < n; i++) {
        memset(maze[i], 0, sizeof(tile) * m);
    }
}

void walk(int n, int m, int d, int sx, int sy) {
    int cnt = 0;
    while (1) {
        // 走一步
        int nx, ny;
        switch (d) {
            case 1:
                nx = sx;
                ny = sy - 1;
                break;
            case 2:
                nx = sx + 1;
                ny = sy;
                break;
            case 3:
                nx = sx;
                ny = sy + 1;
                break;
            case 4:
                nx = sx - 1;
                ny = sy;
                break;
            default:
                abort();
        }
        int border = (nx < 0) || (ny < 0) || (nx >= m) || (ny >= n);
        int wall = maze[ny][nx].type == '*';
        int dir = 1 << d;
        if (border || wall) {
            d++;
            if (d == 5) {
                d = 1;
            }
            if ((maze[sy][sx].dir & dir) != 0) {
                puts("Impossible");
                break;
            }
            maze[sy][sx].dir |= dir;
        } else {
            maze[sy][sx].dir |= dir;
            sx = nx;
            sy = ny;
            cnt++;
            if ((maze[sy][sx].dir & dir) != 0) {
                puts("Impossible");
                break;
            }
            if (maze[sy][sx].type == 'E') {
                printf("%d\n", cnt);
                break;
            }
        }
    }
}

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int n, m, d, sx = -1, sy = -1, has_e = 0;
        scanf("%d%d%d", &n, &m, &d);
        reset_maze(n, m);
        for(int y = 0; y < n; y++) {
            for(int x = 0; x < m; x++) {
                char c;
                scanf(" %c", &c);
                if (c == 'S') {
                    sx = x;
                    sy = y;
                }
                maze[y][x].type = c;
                if (c == 'E') {
                    has_e = 1;
                }
            }
        }
        if (!has_e || sx == -1) {
            puts("Impossible");
            continue;
        }
        walk(n, m, d, sx, sy);
    }
    return 0;
}
